package com.eascs.log.entity;


import java.util.Date;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;


@Entity
@Table(name="o2o_log")
public class Log {
	@Id
	private String id;//
	@Column(name="op_id")
	private String opId;//操作人ID
	@Column(name="op_name")
	private String opName;//操作人
	@Column(name="op_time")
	private Date opTime;//操作时间
	@Column(name="request_uri")
	private String requestUri;//请求URL
	@Column(name="method")
	private String method;//请求方法
	@Column(name="is_success")
	private String isSuccess;//是否操作成功
	@Column(name="remote_addr")
	private String remoteAddr;//操作IP地址
	@Column(name="params")
	private String params;//请求参数
	@Column(name="exception")
	private String exception;//异常
	@Column(name="user_agent")
	private String userAgent;//用户代理
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getOpId() {
		return opId;
	}
	public void setOpId(String opId) {
		this.opId = opId;
	}
	public String getOpName() {
		return opName;
	}
	public void setOpName(String opName) {
		this.opName = opName;
	}
	public Date getOpTime() {
		return opTime;
	}
	public void setOpTime(Date opTime) {
		this.opTime = opTime;
	}
	public String getRequestUri() {
		return requestUri;
	}
	public void setRequestUri(String requestUri) {
		this.requestUri = requestUri;
	}
	public String getMethod() {
		return method;
	}
	public void setMethod(String method) {
		this.method = method;
	}
	public String getIsSuccess() {
		return isSuccess;
	}
	public void setIsSuccess(String isSuccess) {
		this.isSuccess = isSuccess;
	}
	public String getRemoteAddr() {
		return remoteAddr;
	}
	public void setRemoteAddr(String remoteAddr) {
		this.remoteAddr = remoteAddr;
	}
	public String getParams() {
		return params;
	}
	public void setParams(String params) {
		this.params = params;
	}
	public String getException() {
		return exception;
	}
	public void setException(String exception) {
		this.exception = exception;
	}
	public String getUserAgent() {
		return userAgent;
	}
	public void setUserAgent(String userAgent) {
		this.userAgent = userAgent;
	}
	/**
	 * 设置请求参数
	 * @param paramMap
	 */
	@SuppressWarnings("unchecked")
	public void setParams(@SuppressWarnings("rawtypes") Map paramMap){
		if (paramMap == null){
			return;
		}
		StringBuilder params = new StringBuilder();
		for (Map.Entry<String, String[]> param : ((Map<String, String[]>)paramMap).entrySet()){
			params.append(("".equals(params.toString()) ? "" : "&") + param.getKey() + "=");
			String paramValue = (param.getValue() != null && param.getValue().length > 0 ? param.getValue()[0] : "");
			params.append(com.eascs.admin.common.utils.StringUtils.abbr(org.apache.commons.lang3.StringUtils.endsWithIgnoreCase(param.getKey(), "password") ? "" : paramValue, 100));
		}
		this.params = params.toString();
	}
	@Override
	public String toString() {
		return "Log [id=" + id + ", opId=" + opId + ", opName=" + opName + ", opTime=" + opTime + ", requestUri=" + requestUri + ", method=" + method + ", isSuccess=" + isSuccess + ", remoteAddr=" + remoteAddr + ", params=" + params + ", exception=" + exception + ", userAgent=" + userAgent + "]";
	}
}
